package com.xingbg.projectimpl.config.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.mvc.condition.RequestCondition;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;

/**
 * @author yuqi138
 * @version 1.0
 * @Description:一句话描述这个类的作用
 * @date 2021/5/26 14:46
 * @Copyright: 2021 www.jddglobal.com|www.haiyi-info.com Inc.All rights reserved.
 */
@Slf4j
public class LiskovRequestMappingHandlerMapping extends RequestMappingHandlerMapping {

    private String[] basePackages;

    public LiskovRequestMappingHandlerMapping(String[] basePackages) {
        this.basePackages = basePackages;
    }

    @Override
    protected RequestCondition<?> getCustomTypeCondition(Class<?> handlerType) {
        boolean isInChildPackage = false;
        for (String basePackage : basePackages) {
            if(handlerType.getName().contains(basePackage)){
                isInChildPackage = true;
                break;
            }
        }
        return obtainApplicationContext().getBean(LiskovRequestCondition.class, isInChildPackage);
//        return new LiskovRequestCondition(isInBaseProjectPackage);
    }

}
